package de.lehmann.sudoku.data;

@SuppressWarnings("unused") //TODO: Remove suppression of "unused" warnings from Sheet
public class Sheet {
	private static Sheet active = null;
	
	public static Sheet getActive(){
		return active;
	}
	
	private final int WIDTH;
	private final int HEIGHT;
	
	private Tile[][] tileset;
	private Pattern[] rows;
	private Pattern[] columns;
	private Pattern[] boxes;
	
	public Sheet(int width, int height, boolean generating) {
		WIDTH = width;
		HEIGHT = height;
		activate();
		
		tileset = new Tile[getSize()][getSize()];
		rows = new Pattern[getSize()];
		columns = new Pattern[getSize()];
		boxes = new Pattern[getSize()];
		
		generateTileset(generating);
		generatePatterns();
		setupPatterns();
		
	}
	
	private void generateTileset(boolean generating) {
		for(int y = getSize()-1; y >= 0; y--) {
			for(int x = getSize()-1; x >= 0; x--) {
				tileset[y][x] = new Tile(generating);
			}
		}
	}
	
	private void generatePatterns() {
		for(int i = getSize()-1; i >= 0; i--) {
			
		}
	}
	
	private void setupPatterns() {
		int size = getSize();
		for(int y = 0; y < size; y++) {
			for(int x = 0; x < size; x++) {
				int boxIndex = (x/WIDTH) + ((y/HEIGHT)*WIDTH);
				Frame current = new Frame(tileset[y][x], 
						rows[y],
						columns[x],
						boxes[boxIndex]);
				rows[y].add(current);
				columns[x].add(current);
				boxes[boxIndex].add(current);
			}
		}
	}
	
	public void activate() {
		active = this;
	}
	
	public int getHeight() {
		return HEIGHT;
	}
	
	public int getWidth() {
		return WIDTH;
	}
	
	public int getSize() {
		return HEIGHT*WIDTH;
	}
}
